<template>
  <div>
    <a-card :bordered="false">

      <div class="table-page-search-wrapper" >
        <a-form layout="inline">
          <a-row :gutter="24">
            <a-col :md="12" :sm="8">
              <a-form-item :label="$t('m.common.label.begin_date')">
                <ych-date
                  :placeholder="$t('m.common.tip.begin_date_tip')"
                  v-model="beginDate"
                  dateFormat="YYYY-MM-DD"
                  :allowClear="true"
                /> {{$t('m.common.label.to_date')}} <ych-date
                :placeholder="$t('m.common.tip.end_date_tip')"
                v-model="endDate"
                dateFormat="YYYY-MM-DD"
                :allowClear="true"
              />
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="8">
              <a-form-item :label="$t('m.bpm.entity.group')"
              >
                <ych-tree-select
                  ref="treeSelect"
                  placeholder=""
                  v-model="groupIds"
                  dict="act_app_group,group_name,id"
                  pidField="parent_id"
                  pidValue="0"
                  condition='{"group_type":"1"}'
                  :multiple="true"
                >
                </ych-tree-select>


              </a-form-item>
            </a-col>
            <a-col :md="4" :sm="8">
              <a-button type="primary" @click="searchQuery" icon="search">{{ $t('m.common.button.query') }}</a-button>
            </a-col>
          </a-row>
        </a-form>
      </div>

    </a-card>
    <a-card :bordered="true" style="margin-top: 10px;">
      <TaskInstanceCount ref="taskInstanceCount" :beginDate="beginDate" :endDate="endDate" :groupIds="groupIds"></TaskInstanceCount>

    </a-card>

    <a-row :gutter="16">
      <a-col :md="12">
        <a-card :bordered="true" style="margin-top: 10px;">
          <AssigneeMaxCompletedTaskCountTop ref="assigneeMaxCompletedTaskCountTop" :beginDate="beginDate" :endDate="endDate" :groupIds="groupIds"></AssigneeMaxCompletedTaskCountTop>

        </a-card>
      </a-col>
      <a-col :md="12">
        <a-card :bordered="true" style="margin-top: 10px;">
          <AssigneeMaxRunningTaskCountTop ref="assigneeMaxRunningTaskCountTop" :beginDate="beginDate" :endDate="endDate" :groupIds="groupIds"></AssigneeMaxRunningTaskCountTop>
        </a-card>
      </a-col>
    </a-row>

    <a-row :gutter="16">
      <a-col :md="12">
        <a-card :bordered="true" style="margin-top: 10px;">
          <AssigneeTaskAveragetimeTop ref="assigneeTaskAveragetimeTop" :beginDate="beginDate" :endDate="endDate" :groupIds="groupIds"></AssigneeTaskAveragetimeTop>
        </a-card>
      </a-col>
      <a-col :md="12">
        <a-card :bordered="true" style="margin-top: 10px;">
          <AssigneeStartProcessCountTop ref="assigneeStartProcessCountTop" :beginDate="beginDate" :endDate="endDate" :groupIds="groupIds"></AssigneeStartProcessCountTop>
        </a-card>
      </a-col>
    </a-row>
  </div>

</template>

<script>

  import TaskInstanceCount from './modules/TaskInstanceCount'
  import AssigneeMaxCompletedTaskCountTop from './modules/AssigneeMaxCompletedTaskCountTop'
  import AssigneeTaskAveragetimeTop from './modules/AssigneeTaskAveragetimeTop'
  import AssigneeMaxRunningTaskCountTop from './modules/AssigneeMaxRunningTaskCountTop'
  import AssigneeStartProcessCountTop from './modules/AssigneeStartProcessCountTop'
  import YchTreeSelect from '@/components/ych/YchTreeSelect'
  import {YchDate} from '@yuncheng/ych-components'

  export default {
    name: 'TaskAnalyze',
    components: {
      TaskInstanceCount,
      AssigneeMaxCompletedTaskCountTop,
      AssigneeTaskAveragetimeTop,
      AssigneeMaxRunningTaskCountTop,
      AssigneeStartProcessCountTop,
      YchTreeSelect,
      YchDate
    },
    props: {

    },
    data () {
      return {
        beginDate:"",
        endDate:"",
        groupIds:""
      }
    },
    methods: {
      searchQuery(){
        this.$refs.taskInstanceCount.queryData()
        this.$refs.assigneeMaxCompletedTaskCountTop.queryData('1')
        this.$refs.assigneeMaxRunningTaskCountTop.queryData('1')
        this.$refs.assigneeTaskAveragetimeTop.queryData('1')
        this.$refs.assigneeStartProcessCountTop.queryData('1')
      },
      searchReset(){
        this.beginDate = ""
        this.endDate = ""
        this.groupIds = ""
      },
      getFullDate(targetDate) {
        let D, y, m, d;
        D = new Date(targetDate);
        y = D.getFullYear();
        m = D.getMonth() + 1;
        d = D.getDate();
        m = m > 9 ? m : '0' + m;
        d = d > 9 ? d : '0' + d;
        return y + '-' + m + '-' + d;
      },

    },
    created() {
      let beginDate = new Date();
      let currYear = beginDate.getFullYear();
      let currMonth = beginDate.getMonth()+1;
      if(currMonth-5>0){
        currMonth--
      }else{
        currYear--
        currMonth = currMonth-5+12
      }
      let endDate = new Date();
      beginDate.setFullYear(currYear,currMonth-1);
      beginDate.setDate(1);
      this.beginDate = this.getFullDate(beginDate);
      this.endDate = this.getFullDate(endDate);
    },
  }
</script>
